import React, { useRef } from 'react';
import { Button } from 'antd';

import Child from './Children';

interface ReturnVoid {
  getValues: () => void;
}

const ForwordRef: React.FC<any> = () => {
  const childRef = useRef<ReturnVoid>(null);

  const onBtnClick = () => {
    if (childRef && childRef.current) {
      const text = childRef.current.getValues();
      console.log(text);
    }
  };
  return (
    <>
      <Button
        type="primary"
        onClick={() => {
          onBtnClick();
        }}
      >
        调用子组件方法
      </Button>

      <Child ref={childRef} />
    </>
  );
};

export default ForwordRef;
